1 module hip.windowing.window;
2 import hip.api.input.window;
3 
4 version(UWP){}
5 else version(Windows) version = WindowsNative;
6 
7 
8 enum HipWindowFlags
9 {
10     resizable   = 1,
11     fullscreen  = 1<<1,
12     maximizable = 1<<2,
13     minimizable = 1<<4,
14 
15     DEFAULT = resizable | maximizable | minimizable
16 }
17 
18 /**
19 *   This is not a feature complete windowing abstraction. It only has the necessary resources
20 *   for making the engine work. Its feature is not to be an implementation as complete as SDL.
21 *   thus, reducing the external dependencies, binary size and compilation steps.
22 */
23 class HipWindow : IHipWindow
24 {
25     int width, height;
26     HipWindowFlags flags;
27 
28     string[] errors;
29 
30     /** 
31      * HWND on Windows.
32      * MTKView on AppleOS
33      */
34     package void* WindowHandle;
35     version(Windows) void* hwnd(){return WindowHandle;}
36     version(AppleOS) void* MTKView(){return WindowHandle;}
37 
38     this(int width, int height, HipWindowFlags flags)
39     {
40         this.width = width;
41         this.height = height;
42         this.flags = flags;
43     }
44     void start()
45     {
46         version(X11) version(SharedX11)
47             loadX11();
48         getModule!().openWindow(width, height, WindowHandle);
49     }
50 
51     bool startOpenGLContext(int majorVersion = 3, int minorVersion = 3)
52     {
53         //Windows must reinitialize the window if it uses modern gl, so, it must update the window here
54         return getModule!().initializeOpenGL(majorVersion, minorVersion, WindowHandle);
55     }
56     bool destroyOpenGLContext(){return getModule!().destroy_GL_Context();}
57     void pollWindowEvents(){getModule!().poll();}
58     void rendererPresent(){getModule!().swapBuffer();}
59     void setName(string name)
60     {
61         getModule!().setWindowName(name, WindowHandle, errors);
62     }
63     void setSize(uint width, uint height) @nogc
64     {
65         getModule!().setWindowSize(width, height, WindowHandle, errors);
66     }
67     int[2] getSize()
68     {
69         return getModule!().getWindowSize(WindowHandle, errors);
70     }
71     void setVSyncActive(bool active)
72     {
73         //Windows must reinitialize the window if it uses modern gl, so, it must update the window here
74         getModule!().setVsyncActive(active, WindowHandle, errors);
75 
76     }
77     void setFullscreen(bool fullscreen)
78     {
79         getModule!().setFullscreen(fullscreen, WindowHandle, errors);
80     }
81     
82     void show()
83     {
84         getModule!().show(WindowHandle);
85     }
86     void hide(){}
87     void exit()
88     {
89         version(SharedX11)
90             unloadX11();
91     } 
92 }
93 
94 private template getModule()
95 {
96     version(WindowsNative)
97         import getModule = hip.windowing.platforms.windows;
98     else version(X11)
99         import getModule = hip.windowing.platforms.x11;
100     else version(WebAssembly)
101         import getModule = hip.windowing.platforms.browser;
102     else version(AppleOS)
103         import getModule = hip.windowing.platforms.appleos;
104     else
105         import getModule = hip.windowing.platforms.null_;
106 }